/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__wtc_analyze_direct.c                           */
/*  NOTE      =                                                    */
/*  DATE      = 2016/02/24 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../src/module/tuxedowtc/config.h"
#include "../test_wtc_comm.h"
#include <tuxedowtc/wtc_core.h>
#include <tuxedowtc/wtc_header.h>
#include <tuxedowtc/wtc_comm.h>
#include <tuxedowtc/wtc_packet.h>
#include <frct_comm.h>
#include <apmtest_comm.h>

extern int __wtc_analyze_direct(char *p_payload, unsigned int ui_payload_len);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    char *p_bin = (char *) "739038420000000e00000001ffffffff0000000000000000000000010000021c0000005700000054000000430000004c0000006f00000063000000610000006c000000410000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004800000014000000010001001b";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__wtc_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_CLIENT2SRV);
}

static void __case2(void)
{
    char *p_bin = (char *) "739038420000000f00000001ffffffff0000000000000000000000010000022000000073000000690000006d000000700000006100000070000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007900000014000000010000001b";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__wtc_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_SRV2CLIENT);
}

static void __case3(void)
{
    char *p_bin = (char *) "000000000000001400000000fffffffe000001b0800000010000000000000000910398580000001100010000000000000000002c0000123000000006535452494e47000000000000000000096c6f77657263617365000000001300000000005400001230ffffd8f0000000487fffffff00000003000000000000001003c9cee40000bea10bc9ced50000000900000001000000000dc9cee5000000120000000a00006c5e1fa3e5e6703a00000007000000000058000012300000000100000002ffffffff0000000000000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000007544f555050455200000a0000000000ac000012300000001e00000020000000000000000000000000000000000000006c0000005e0000001fffffffa3ffffffe5ffffffe6000000700000003a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a5754434c6f63616c41500000";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__wtc_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_CLIENT2SRV);
}

static void __case4(void)
{
    char *p_bin = (char *) "10000000000000140324800400000000000000b8800000010000000000000000910398580000001100030403000000000000002c0000123000000006535452494e47000000000000000000094c4f574552434153450000000007000300000060000012300000000200000002ffffffff000000000000000000000001000000000000000000000000032800070328800a0000000000020000000000000096000300003757000000100480240304802403ffffffffffffffff";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__wtc_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_SRV2CLIENT);
}

static void __case5(void)
{
    char *p_bin = (char *) "000000000000001400000000fffffffe0000017c80000001000000000000000091039858ffffffff00090000001300000000005400001230ffffd8f0000000487fffffff00000003000000000000001003c9cee40000bea10bc9ced50000000900000001000000000dc9cee5000000120000000a00006c5e1fa3e5e6703a00000007000000000050000012300000000900000003ffffffff0000000000000020000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000a0000000000ac000012300000000000000020000000000000000000000000000000000000006c0000005e0000001fffffffa3ffffffe5ffffffe6000000700000003a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a5754434c6f63616c41500000";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__wtc_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_CLIENT2SRV);
}

static void __case6(void)
{
    char *p_bin = (char *) "000000000000001400000000000000000000012880000001000000000000000091039858ffffffff000b0403000a0003000000ac000012300000000000000020000000000000000000000000000000000000006c0000005e0000001fffffffa3ffffffe5ffffffe6000000700000003a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a5754434c6f63616c415000000007000200000050000012300000000a00000000ffffffff0000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__wtc_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_UNKNOWN);
}

int add_suite__wtc_analyze_direct(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __wtc_analyze_direct()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
